package com.dlc.demo.daiqianma.activity;

import android.os.Bundle;
import android.support.annotation.ColorInt;
import android.widget.TextView;

import com.dlc.demo.daiqianma.R;
import com.dlc.demo.daiqianma.entity.ApplyForLoanSubmitStateEntity;
import com.dlc.demo.daiqianma.iview.IApplyForLoanView;
import com.dlc.demo.daiqianma.presenter.ApplyForLoanPresenter;

import butterknife.BindColor;
import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 审批Activity
 */
public class ApplyForLoanActivity extends UserActivity implements IApplyForLoanView {
    @BindView(R.id.tvBaseInfo)
    public TextView tvBaseInfo;
    @BindView(R.id.tvOccupation)
    public TextView tvOccupation;
    @BindView(R.id.tvCredit)
    public TextView tvCredit;
    @BindView(R.id.tvAsset)
    public TextView tvAsset;

    @BindColor(R.color.red)
    int colorRed;
    @BindColor(R.color.colorPrimary)
    int colorPrimary;

    private ApplyForLoanPresenter applyForLoanPresenter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_apply_for_loan);

        applyForLoanPresenter = new ApplyForLoanPresenter();
        applyForLoanPresenter.attachView(this);
        //view注入框架
        ButterKnife.bind(this);
        setHeadTitle("申请贷款");
    }

    @Override
    protected void onStart() {
        super.onStart();
        //获取最新的提交状态
        applyForLoanPresenter.getApplyForLoanState();
    }

    @Override
    public void showSubmitedInfo(ApplyForLoanSubmitStateEntity state) {
        updateTextView(tvBaseInfo,state.getIsBaseInfoSubmit());
        updateTextView(tvOccupation,state.getIsOccupationInfoSubmit());
        updateTextView(tvCredit,state.getIsCreditInfoSubmit());
        updateTextView(tvAsset,state.getIsAssetInfoSubmit());
    }

    /**
     * 更新是否提交状态
     * @param tv
     * @param state
     */
    private void updateTextView(TextView tv,int state){
        if (state==1){
            tv.setText("已提交");
            tv.setTextColor(colorRed);
        }else{
            tv.setText("去提交");
            tv.setTextColor(colorPrimary);
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        applyForLoanPresenter.detachView();
    }
}
